package pe.gob.sedapal.scmultimedia.rcp.action;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.jpedal.PdfDecoder;

import pe.gob.sedapal.scmultimedia.rcp.view.servicios.PdfView;


public class ScaleInAction extends Action implements IWorkbenchAction {
	private static final String ID = "pe.gob.sedapal.scmultimedia.rcp.action.ScaleInAction";  
	private float scaling;
	private PdfDecoder decodePDF;
	private int currentPage;
	
	public ScaleInAction(){  
		setId(ID);  
	}  
	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}
	@Override
	public void run() {
		PdfView view=(PdfView)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(PdfView.ID);  
		decodePDF=view.getDecodePDF();
		scaling=view.getScaling();
		currentPage=view.getCurrentPage();
		setScale(1.5f,view);
	}
	
	private void setScale(float rescale,PdfView view) {
		float newFloat=scaling*rescale;
		
		/**
		 * rescale if in sensible range
		 */
		if(newFloat>0.1f && newFloat<10){
			scaling=scaling*rescale;
			
			
			decodePDF.setPageParameters(scaling, currentPage); 
			decodePDF.updateUI();
			view.repaint();
			
		}
	}
	
	

}
